<?php
/* Author: tbloc@cantho.gov.vn */
class Chi_tiet_nhap{  
//Properties
private $NHAP_ID;
private $HH_ID;
private $CT_DON_GIA;
private $CT_SO_LUONG;
private $CT_THANH_TIEN;
private $IS_ACTIVE;
//properties set get 
public function setNHAP_ID($NHAP_ID) 
{
	$this->NHAP_ID = $NHAP_ID;
}
public function getNHAP_ID()
{
	return $this->NHAP_ID;
}	        
public function setHH_ID($HH_ID) 
{
	$this->HH_ID = $HH_ID;
}
public function getHH_ID()
{
	return $this->HH_ID;
}	        
public function setCT_DON_GIA($CT_DON_GIA) 
{
	$this->CT_DON_GIA = $CT_DON_GIA;
}
public function getCT_DON_GIA()
{
	return $this->CT_DON_GIA;
}	        
public function setCT_SO_LUONG($CT_SO_LUONG) 
{
	$this->CT_SO_LUONG = $CT_SO_LUONG;
}
public function getCT_SO_LUONG()
{
	return $this->CT_SO_LUONG;
}	        
public function setCT_THANH_TIEN($CT_THANH_TIEN) 
{
	$this->CT_THANH_TIEN = $CT_THANH_TIEN;
}
public function getCT_THANH_TIEN()
{
	return $this->CT_THANH_TIEN;
}	        
public function setIS_ACTIVE($IS_ACTIVE) 
{
	$this->IS_ACTIVE = $IS_ACTIVE;
}
public function getIS_ACTIVE()
{
	return $this->IS_ACTIVE;
}	        
//crud methods
public function insert($db = null) {
	if ($db != null){
	$sql = "INSERT INTO `chi_tiet_nhap`(                        
			`NHAP_ID`, 
				`HH_ID`, 
				`CT_DON_GIA`, 
				`CT_SO_LUONG`, 
				`CT_THANH_TIEN`, 
				`IS_ACTIVE` 
		)
	VALUES(
    		:NHAP_ID, 
	    		:HH_ID, 
	    		:CT_DON_GIA, 
	    		:CT_SO_LUONG, 
	    		:CT_THANH_TIEN, 
	    		:IS_ACTIVE 
	    );";
	$parameters = array(
			":NHAP_ID", 
				":HH_ID", 
				":CT_DON_GIA", 
				":CT_SO_LUONG", 
				":CT_THANH_TIEN", 
				":IS_ACTIVE" 
		);
    $values = array(  
    		$this->getNHAP_ID(), 
	    		$this->getHH_ID(), 
	    		$this->getCT_DON_GIA(), 
	    		$this->getCT_SO_LUONG(), 
	    		$this->getCT_THANH_TIEN(), 
	    		$this->getIS_ACTIVE() 
	    );
    $types = array(
    	PDO::PARAM_INT, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_INT, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_STR, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_INT, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_STR, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_INT, //Kiem tra lai kieu du lieu nhe
    );
	$lastInsertID = $db->executeNonQuery($sql, $parameters, $values, $types);
	
    }
}
	
	public function delete($db = null) {
	    if ($db != null) {
	        $sql = "DELETE FROM `chi_tiet_nhap`
	                where `NHAP_ID` = :NHAP_ID;";
	        $parameters = array(":NHAP_ID");
	        $values = array($this->getNHAP_ID());
	        $types = array(PDO::PARAM_INT);//Kiem tra lai kieu du lieu nhe
	        $result = $db->executeNonQuery($sql, $parameters, $values, $types);
	        return $result;
	    }
	}
	
	public function update($db = null) {
	        if ($db != null) {
	            $sql = "UPDATE `chi_tiet_nhap` SET 
			`NHAP_ID`=:NHAP_ID,
				`HH_ID`=:HH_ID,
				`CT_DON_GIA`=:CT_DON_GIA,
				`CT_SO_LUONG`=:CT_SO_LUONG,
				`CT_THANH_TIEN`=:CT_THANH_TIEN,
				`IS_ACTIVE`=:IS_ACTIVE
			WHERE `HH_ID` = :HH_ID;";
	            $parameters = array(
			":NHAP_ID",
				":HH_ID",
				":CT_DON_GIA",
				":CT_SO_LUONG",
				":CT_THANH_TIEN",
				":IS_ACTIVE"
			);
	// Kiem tra dau , nhe
	$values = array(  
			$this->getNHAP_ID(),
				$this->getHH_ID(),
				$this->getCT_DON_GIA(),
				$this->getCT_SO_LUONG(),
				$this->getCT_THANH_TIEN(),
				$this->getIS_ACTIVE()
		);
    $types = array(
    	PDO::PARAM_INT, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_INT, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_STR, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_INT, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_STR, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_INT, //Kiem tra lai kieu du lieu nhe
    );
	$result = $db->executeNonQuery($sql, $parameters, $values, $types);
	return $result;
	        }
	 }
	 
	public function getByID($chi,$hanghoa,$db = null) {
	if ($db != null) {
	$sql = "SELECT
			`NHAP_ID`,
				`HH_ID`,
				`CT_DON_GIA`,
				`CT_SO_LUONG`,
				`CT_THANH_TIEN`,
				`IS_ACTIVE`
			FROM `chi_tiet_nhap` WHERE `NHAP_ID`=:NHAP_ID AND `HH_ID` = :HH_ID and `is_active`=1;";
	$parameters = array(":NHAP_ID",":HH_ID");
	$values = array($chi,$hanghoa);
	$types = array(PDO::PARAM_INT,PDO::PARAM_INT);//kiem tra lai kieu du lieu nhe
	$rows = $db->executeQuery($sql, $parameters, $values, $types);
        
	if ($rows != null) {
	$row = $rows->fetch();
        $chitietnhap=new Chi_tiet_nhap();
		$chitietnhap->setNHAP_ID($row->NHAP_ID);
		$chitietnhap->setHH_ID($row->HH_ID);
		$chitietnhap->setCT_DON_GIA($row->CT_DON_GIA);
		$chitietnhap->setCT_SO_LUONG($row->CT_SO_LUONG);
		$chitietnhap->setCT_THANH_TIEN($row->CT_THANH_TIEN);
		$chitietnhap->setIS_ACTIVE($row->IS_ACTIVE);
	
                return $chitietnhap;
        }
	
		}
	}
	
        
        public function getByID_ChiTiet($chi,$db = null) {
	if ($db != null) {
	$sql = "SELECT
			`NHAP_ID`,
				`HH_ID`,
				`CT_DON_GIA`,
				`CT_SO_LUONG`,
				`CT_THANH_TIEN`,
				`IS_ACTIVE`
			FROM `chi_tiet_nhap` WHERE `NHAP_ID`=:NHAP_ID  and `is_active`=1;";
	$parameters = array(":NHAP_ID");
	$values = array($chi);
	$types = array(PDO::PARAM_INT);//kiem tra lai kieu du lieu nhe
	$rows = $db->executeQuery($sql, $parameters, $values, $types);
        
	if ($rows != null) {
        while ($row = $rows->fetch()) {
        $obj = new Chi_tiet_nhap();
             $obj->setNHAP_ID($row->NHAP_ID);
                     $obj->setHH_ID($row->HH_ID);
                     $obj->setCT_DON_GIA($row->CT_DON_GIA);
                     $obj->setCT_SO_LUONG($row->CT_SO_LUONG);
                     $obj->setCT_THANH_TIEN($row->CT_THANH_TIEN);
                     $obj->setIS_ACTIVE($row->IS_ACTIVE);
                    $objects[] = $obj;
        }
        return $objects;
        }
	
		}
	}
        
        
        
	public function getList($db = null) {
	if ($db != null) {
    $sql = "SELECT
			`NHAP_ID`,
				`HH_ID`,
				`CT_DON_GIA`,
				`CT_SO_LUONG`,
				`CT_THANH_TIEN`,
				`IS_ACTIVE`
			FROM `chi_tiet_nhap` WHERE `is_active`=1;";
    $rows = $db->executeQuery($sql);
    $objects = array();
    if ($rows != null) {
    while ($row = $rows->fetch()) {
    $obj = new Chi_tiet_nhap();
    	 $obj->setNHAP_ID($row->NHAP_ID);
		 $obj->setHH_ID($row->HH_ID);
		 $obj->setCT_DON_GIA($row->CT_DON_GIA);
		 $obj->setCT_SO_LUONG($row->CT_SO_LUONG);
		 $obj->setCT_THANH_TIEN($row->CT_THANH_TIEN);
		 $obj->setIS_ACTIVE($row->IS_ACTIVE);
		$objects[] = $obj;
    }
    return $objects;
    }
        }
    }
}
?>

